package com.itheima.handler;

import com.itheima.entity.Result;
import com.itheima.utils.ResultUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * 统一异常处理类
 */
@ControllerAdvice
public class BaseExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public String error(Exception e){
        e.printStackTrace();
        return ResultUtil.result(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
    }
}